#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}



void Widget::on_pushButton_new_clicked()
{
    //1.先创建一个Widget控件
    QWidget* w=new QWidget();
    //2.获取现在有几个Tab
    int num=ui->tabWidget->count();
    //3.添加到Tab中
    ui->tabWidget->addTab(w,QString("第")+QString::number(num+1)+QString("页"));
    //4.设置一个label
    QLabel* label=new QLabel(w);
    label->setText("这是第"+QString::number(num+1)+"页");
    label->resize(100,50);
    //5.设置新的标签页被选中
    ui->tabWidget->setCurrentIndex(num);
}

void Widget::on_pushButton_close_clicked()
{
     //1.先获取要关闭的标签页
    int pos=ui->tabWidget->currentIndex();
    if(pos<0)
    {
        return;
    }
    //2.关闭标签页
    ui->tabWidget->removeTab(pos);


}
